package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.TbFaultType;
import com.ruoyi.system.service.ITbFaultTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.TbFault;
import com.ruoyi.system.service.ITbFaultService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 故障码Controller
 * 
 * @author ruoyi
 * @date 2023-06-25
 */
@RestController
@RequestMapping("/fault")
public class TbFaultController extends BaseController
{
    @Autowired
    private ITbFaultService tbFaultService;

    @Autowired
    private ITbFaultTypeService tbFaultTypeService;

    /**
     * 查询故障码列表
     */
    @RequiresPermissions("system:fault:list")
    @GetMapping("/list")
    public TableDataInfo list(TbFault tbFault)
    {
        startPage();
        List<TbFault> list = tbFaultService.selectTbFaultList(tbFault);
        return getDataTable(list);
    }

    /**
     * 导出故障码列表
     */
    @RequiresPermissions("system:fault:export")
    @Log(title = "故障码", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbFault tbFault)
    {
        List<TbFault> list = tbFaultService.selectTbFaultList(tbFault);
        ExcelUtil<TbFault> util = new ExcelUtil<TbFault>(TbFault.class);
        util.exportExcel(response, list, "故障码数据");
    }

    /**
     * 获取故障码详细信息
     */
    @RequiresPermissions("system:fault:query")
    @GetMapping(value = "/{faultId}")
    public AjaxResult getInfo(@PathVariable("faultId") Long faultId)
    {
        return success(tbFaultService.selectTbFaultByFaultId(faultId));
    }

    /**
     * 新增故障码
     */
    @RequiresPermissions("system:fault:add")
    @Log(title = "故障码", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbFault tbFault)
    {
        return toAjax(tbFaultService.insertTbFault(tbFault));
    }

    /**
     * 修改故障码
     */
    @RequiresPermissions("system:fault:edit")
    @Log(title = "故障码", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbFault tbFault)
    {
        return toAjax(tbFaultService.updateTbFault(tbFault));
    }

    /**
     * 删除故障码
     */
    @RequiresPermissions("system:fault:remove")
    @Log(title = "故障码", businessType = BusinessType.DELETE)
	@DeleteMapping("/{faultIds}")
    public AjaxResult remove(@PathVariable Long[] faultIds)
    {
        return toAjax(tbFaultService.deleteTbFaultByFaultIds(faultIds));
    }


    /**
     * 查询故障分类列表
     */
    @RequiresPermissions("system:fault:typeList")
    @GetMapping("/typeList")
    public TableDataInfo typeList(TbFault tbFault)
    {
        startPage();
        List<TbFaultType> list = tbFaultTypeService.selectTbFaultTypeList();
        return getDataTable(list);
    }

}
